home *** CD-ROM | disk | FTP | other *** search
- /*******************************************
- *
- * high_pixel(..
- *
- * This function replaces the pixel at
- * the center of a 3x3, 5x5, etc. area
- * with the max for that area.
- *
- *******************************************/
-
- high_pixel(in_name, out_name, the_image, out_image,
- il, ie, ll, le, size)
- char in_name[], out_name[];
- int il, ie, ll, le, size;
- short the_image[ROWS][COLS],
- out_image[ROWS][COLS];
- {
- int a, b, count, i, j, k,
- length, sd2, sd2p1, ss, width;
- short *elements;
- struct tiff_header_struct image_header;
-
- sd2 = size/2;
- sd2p1 = sd2 + 1;
-
- /**********************************************
- *
- * Allocate the elements array large enough
- * to hold size*size shorts.
- *
- **********************************************/
-
- ss = size*size;
- elements = (short *) malloc(ss * sizeof(short));
-
- if(does_not_exist(out_name)){
- printf("\n\n output file does not exist %s",
- out_name);
- read_tiff_header(in_name, &image_header);
- round_off_image_size(&image_header,
- &length, &width);
- image_header.image_length = length*ROWS;
- image_header.image_width = width*COLS;
- create_allocate_tiff_file(out_name, &image_header,
- out_image);
- } /* ends if does_not_exist */
- read_tiff_image(in_name, the_image, il, ie, ll, le);
-
- /***************************
- *
- * Loop over image array
- *
- ****************************/
-
- printf("\n");
- for(i=sd2; i<ROWS-sd2; i++){
- if( (i%10) == 0) printf("%d ", i);
- for(j=sd2; j<COLS-sd2; j++){
- count = 0;
- for(a=-sd2; a<sd2p1; a++){
- for(b=-sd2; b<sd2p1; b++){
- elements[count] = the_image[i+a][j+b];
- count++;
- }
- }
- sort_elements(elements, &ss);
- out_image[i][j] = elements[ss-1];
- } /* ends loop over j */
- } /* ends loop over i */
-
- fix_edges(out_image, sd2);
-
- write_array_into_tiff_image(out_name, out_image,
- il, ie, ll, le);
-
- free(elements);
-
- } /* ends high_pixel */
-
-
-
-
- /*******************************************
- *
- * low_pixel(..
- *
- * This function replaces the pixel at
- * the center of a 3x3, 5x5, etc. area
- * with the min for that area.
- *
- *******************************************/
-
- low_pixel(in_name, out_name, the_image, out_image,
- il, ie, ll, le, size)
- char in_name[], out_name[];
- int il, ie, ll, le, size;
- short the_image[ROWS][COLS],
- out_image[ROWS][COLS];
-
- {
- int a, b, count, i, j, k,
- length, sd2, sd2p1, ss, width;
- short *elements;
- struct tiff_header_struct image_header;
-
- sd2 = size/2;
- sd2p1 = sd2 + 1;
-
- /**********************************************
- *
- * Allocate the elements array large enough
- * to hold size*size shorts.
- *
- **********************************************/
-
- ss = size*size;
- elements = (short *) malloc(ss * sizeof(short));
-
- if(does_not_exist(out_name)){
- printf("\n\n output file does not exist %s",
- out_name);
- read_tiff_header(in_name, &image_header);
- round_off_image_size(&image_header,
- &length, &width);
- image_header.image_length = length*ROWS;
- image_header.image_width = width*COLS;
- create_allocate_tiff_file(out_name, &image_header,
- out_image);
- } /* ends if does_not_exist */
-
- read_tiff_image(in_name, the_image, il, ie, ll, le);
-
- /***************************
- *
- * Loop over image array
- *
- ****************************/
-
- printf("\n");
- for(i=sd2; i<ROWS-sd2; i++){
- if( (i%10) == 0) printf("%d ", i);
- for(j=sd2; j<COLS-sd2; j++){
- count = 0;
- for(a=-sd2; a<sd2p1; a++){
- for(b=-sd2; b<sd2p1; b++){
- elements[count] = the_image[i+a][j+b];
- count++;
- }
- }
- sort_elements(elements, &ss);
- out_image[i][j] = elements[0];
- } /* ends loop over j */
- } /* ends loop over i */
-
- fix_edges(out_image, sd2);
-
- write_array_into_tiff_image(out_name, out_image,
- il, ie, ll, le);
-
- free(elements);
-
- } /* ends low_pixel */
-
-